home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / mus / misc / copyist.lha / txt2c.c < prev   
C/C++ Source or Header  |  1994-01-10  |  1KB  |  87 lines

  1. #include "vd0:stdio.h"
  2. #define BUF_SIZE   32
  3. char s[16];
  4. char *t_pos=0;
  5. char token[16];
  6. int copyist[3];
  7. FILE *fpin,*fpout;
  8.  
  9. main(argc,argv)
  10. int argc;
  11. char *argv[];
  12. {
  13. if((fpin=fopen(argv[1],"r"))==0)  {
  14.     printf("Cannot open file %s\n",argv[1]);
  15.     exit(0);
  16.     }
  17. if((fpout=fopen(argv[2],"w"))==0)  {
  18.       printf("Cannot open file %s\n",argv[2]);
  19.     exit(0);
  20.     }
  21. while (fgets(s,13,fpin))
  22.       {
  23.       t_pos = s;
  24.           numconvert();
  25.       WriteCopyist();
  26.           }
  27. WriteEndFile();
  28. fclose(fpin);
  29. fclose(fpout);
  30. }    
  31.  
  32. numconvert()
  33. {
  34. int x;
  35. get_token();
  36. copyist[0] = atoi(token);
  37. get_token();
  38. copyist[1] = atoi(token);
  39. get_token();
  40. copyist[2] = atoi(token);
  41. }
  42.  
  43. get_token()
  44. {
  45.   char *p;
  46.   p=token;
  47.   while(*t_pos==' ') t_pos++;
  48.     if(*t_pos=='\0')  {
  49.     *p++='\0';
  50.     *p='\0';
  51.     return;
  52.   }  
  53.   while(*t_pos!=' ' && *t_pos!='\0')  {
  54.     *p=*t_pos++;
  55.     p++;
  56.     }
  57.   *p='\0';  
  58.  }
  59.  
  60.  
  61.  
  62. WriteCopyist()
  63. {
  64. short x,y,z;
  65. int total,xpos,ypos;
  66.  xpos = copyist[0];
  67.  ypos = copyist[1];
  68.  z = copyist[2];
  69. total = 3200 + ((xpos-1) + ((ypos-1) * 160));
  70. x = total / 256;
  71. y = total - (x * 256);
  72. fprintf(fpout,"%c",x);
  73. fprintf(fpout,"%c",y);
  74. fprintf(fpout,"%c",z);
  75. }
  76.  
  77.  
  78. WriteEndFile()
  79. {
  80. fprintf(fpout,"%c",255);
  81. fprintf(fpout,"%c",255);
  82. fprintf(fpout,"%c",255);
  83. fprintf(fpout,"%c",255);
  84. fprintf(fpout,"%c",255);
  85. fprintf(fpout,"%c",255);
  86. }
  87.